/* Example of use

var tip = new Tip(document.getElementById("tip"), document.body, 100, 25);

tip.setData = function()
{
	this.tipElement.innerHTML = this.srcElement.innerHTML;
}

var itemLinks = document.getElementsByName("itemLink");

for (var i = 0; i < itemLinks.length; i++)
{
	var itemLink = itemLinks.item(i);
	tip.attachEvents(itemLink);
}

*/

function Tip(tipElement, clientElement, tipWidth, tipHeight)
{
	Tip.prototype.tipElement = tipElement;
	Tip.prototype.clientElement = clientElement;
	Tip.prototype.tipWidth = tipWidth;
	Tip.prototype.tipHeight = tipHeight;

	Tip.prototype.srcElement = null;
	Tip.prototype.clientY = 0;
	Tip.prototype.clientX = 0;
	Tip.prototype.y = 0;
	Tip.prototype.x = 0;
	Tip.prototype.clientWidth = this.clientElement.clientWidth;
	Tip.prototype.clientHeight = this.clientElement.clientHeight;
	Tip.prototype.scrollLeft = this.clientElement.scrollLeft;
	Tip.prototype.scrollTop = this.clientElement.scrollTop;

	Tip.prototype.tipIndent = 3; // px, indent between tip and mouse pointer

	Tip.prototype.timeout = 1000;
	Tip.prototype.timeoutId = -1;
}

Tip.prototype.onMouseOver = function(event)
{
	this.srcElement = (BrowserInfo.IsIE ? event.srcElement : event.target);
	this.setData();

	var self = this;
	this.hideTip();
	if (this.timeoutId != -1) { clearTimeout(this.timeoutId); this.timeoutId = -1; }
	this.timeoutId = setTimeout(function () { self.onShow(); }, this.timeout);
}

Tip.prototype.onMouseOut = function(event)
{
	this.srcElement = (BrowserInfo.IsIE ? event.srcElement : event.target);
	this.hideTip();
	if (this.timeoutId != -1) { clearTimeout(this.timeoutId); this.timeoutId = -1; }
	this.clearData();
}

Tip.prototype.onMouseMove = function (event)
{
	this.srcElement = (BrowserInfo.IsIE ? event.srcElement : event.target);
	this.clientY = event.clientY;
	this.clientX = event.clientX;
	this.clientWidth = this.clientElement.clientWidth;
	this.clientHeight = this.clientElement.clientHeight;
	this.scrollLeft = this.clientElement.scrollLeft;
	this.scrollTop = this.clientElement.scrollTop;
	this.x = event.clientX + this.scrollLeft;
	this.y = event.clientY + this.scrollTop;

	this.moveTip();
}

Tip.prototype.onShow = function()
{
	this.moveTip();
	this.showTip();
	clearTimeout(this.timeoutId);
}

Tip.prototype.moveTip = function()
{
	var posTop;
	var posLeft;

	if ((this.clientX + this.tipWidth) > this.clientWidth) posLeft = (this.x - this.tipWidth - this.tipIndent);
	else posLeft = (this.x + this.tipIndent);

	if ((this.clientY + this.tipHeight) > this.clientHeight) posTop = (this.y - this.tipHeight - this.tipIndent);
	else posTop = (this.y + this.tipIndent);

	this.tipElement.style.top = posTop;
	this.tipElement.style.left = posLeft;
}

Tip.prototype.setData = function()
{
}

Tip.prototype.clearData = function()
{
}

Tip.prototype.hideTip = function()
{
	this.tipElement.style.display = "none";
	this.tipElement.style.visible = "hidden";
}

Tip.prototype.showTip = function()
{
	this.tipElement.style.display = "inline";
	this.tipElement.style.visible = "";
}

Tip.prototype.attachEvents = function(element)
{
	var self = this;

	if (element.attachEvent) // ie
	{
		element.attachEvent("onmouseover", function (event) { self.onMouseOver(event); });
		element.attachEvent("onmouseout", function (event) { self.onMouseOut(event); });
		element.attachEvent("onmousemove", function (event) { self.onMouseMove(event); });
	}
	else if (element.addEventListener) // ff
	{
		element.addEventListener("mouseover", function (event) { self.onMouseOver(event); }, false);
		element.addEventListener("mouseout", function (event) { self.onMouseOut(event); }, false);
		element.addEventListener("mousemove", function (event) { self.onMouseMove(event); }, false);
	}
	else // both
	{
		element.onmouseover = function (event) { self.onMouseOver(event); };
		element.onmouseout = function (event) { self.onMouseOut(event); };
		element.onmousemove = function (event) { self.onMouseMove(event); };
	}
}
